﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.Core.Modelling.Primitives;
using ITAP.ShprossesBuilder.Calculations;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Modelling.Measurement
{
    public enum DimensionPosition
    {
        Horizontal, 
        Vertical, 
        Other
    }

    public class SizeDimension : Dimension
    {
        protected ModelPoint initialStartPoint;

        public ModelPoint InitialStartPoint
        {
            get { return initialStartPoint; }
            set { initialStartPoint = value; }
        }
        protected ModelPoint initialEndPoint;

        public ModelPoint InitialEndPoint
        {
            get { return initialEndPoint; }
            set { initialEndPoint = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="initialStartPoint">Точка, от которой надо будет проводить выносную линию.</param>
        /// <param name="initialEndPoint">Точка, от которой надо будет проводить выносную линию.</param>
        public SizeDimension(IEndedPrimitive primitive, ModelPoint initialStartPoint, ModelPoint initialEndPoint) 
            : base(primitive)
        {
            this.initialStartPoint = (ModelPoint)initialStartPoint.Clone();
            this.initialEndPoint = (ModelPoint)initialEndPoint.Clone();
        }

        public SizeDimension(IEndedPrimitive primitive) : this(primitive, primitive.StartPoint, primitive.EndPoint)
        {            
        }

        #region IEquatable<Dimension> Members

        public override bool Equals(Dimension other)
        {
            if(!(other is SizeDimension))
                return false;

            SizeDimension _other = other as SizeDimension;
            if(other is SizeDimension && base.Equals(other) && this.InitialStartPoint.Equals(_other.InitialStartPoint) && this.InitialEndPoint.Equals(_other.InitialEndPoint))
            {
                return true;
            }
            else
                return false;
        }
        #endregion

        public override void AcceptVisitor(IDimensionVisitor visitor)
        {
            visitor.Visit(this);
        }

        public override bool IsCollide(Dimension other)
        {
            if (!(other is SizeDimension))
                return false;
            else
                return base.IsCollide(other);
        }

        public override object Clone()
        {
            SizeDimension clone = new SizeDimension((IEndedPrimitive)this.Primitive.Clone());
            clone.Level = this.level;
            clone.side = this.side;
            clone.InitialStartPoint = (ModelPoint)this.InitialStartPoint.Clone();
            clone.InitialEndPoint = (ModelPoint)this.InitialEndPoint.Clone();
            return clone;
        }
    }
}
